﻿define(['knockout', 'draggablePrototype', 'refData'],
    function (ko, DraggablePrototype, refData) {
        function GlyphModel (data) {
            "use strict";

            var self = this;

            self.height = ko.observable(data ? data.height : 13);
            self.angle = ko.observable(data ? data.angle : 0);
            self.fontId = ko.observable(data ? data.fontId : 0);
            self.char = ko.observable(data ? data.char : 'A');

            self.fontSize = ko.computed(function(){
            	return self.height() - 2;
            });

            self.fontFamily = ko.computed({
            	read: function(){
            		return refData.fonts[self.fontId()];
            	},
            	write: function(value){
            		self.fontId(refData.fonts.indexOf(value));
            	},
            	owner: self
            });

            self.rawData =  ko.computed({
                read: function()
            {
                var rawData = self.prototype.rawData();
                rawData.height = self.height();
                rawData.angle = self.angle();
                rawData.fontId = self.fontId();
                rawData.char = self.char();
                return rawData;
            },
            write: null,
            owner: self,
            deferEvaluation: true});
        };

        GlyphModel.prototype = new DraggablePrototype();
        return GlyphModel;
    });